package com.排序算法;

import java.util.Random;

public class 选择排序 {

    public static void selectSort(int arrays[]) {
        int index, temp;
        for (int i = 0; i < arrays.length - 1; i++) {
            index = i;
            for (int j = i + 1; j < arrays.length; j++) {
                if (arrays[j] < arrays[index]) {
                    index = j;
                }
            }
            if (index != i) {
                temp = arrays[index];
                arrays[index] = arrays[i];
                arrays[i] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int arrays[] = new int[100];
        Random random = new Random();
        for (int i = 0; i < arrays.length; i++) {
            arrays[i] = random.nextInt(1000);
        }
        selectSort(arrays);
        System.out.println("选择排序算法结果：");
        for (int i = 0; i < arrays.length; i++) {
            if (i % 10 == 0) {
                System.out.println(" ");
            }
            System.out.print(arrays[i] + " ");
        }
    }
}
/**
 * 选择排序算法结果：
 * <p>
 * 1 30 32 47 57 65 70 83 89 92
 * 98 107 109 111 113 121 123 140 148 177
 * 182 185 205 208 234 234 239 244 271 279
 * 281 304 323 338 344 345 346 356 367 368
 * 391 400 402 413 433 456 484 487 488 503
 * 516 525 535 542 544 548 556 586 597 607
 * 615 642 656 674 689 694 733 738 739 750
 * 753 768 772 774 776 778 782 804 827 834
 * 840 849 870 873 876 876 877 880 907 912
 * 919 931 933 945 967 976 988 996 997 997
 */